package org.wuqi.microweb.api.testmethod;

import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * @author jjj
 * @program: earnest-money
 * @description:TODO
 * @date 2024-01-03 16:04:56
 */
@Component
public class CountDownLatchExample implements Runnable {
    private CountDownLatch latch ;
    public CountDownLatchExample() {
    }
    public CountDownLatchExample(CountDownLatch latch) {
        this.latch = latch;
    }
    @Override
    public void run() {
        System.out.println("Task started");
        // 模拟耗时操作
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Task completed");
        latch.countDown(); // 操作完成后计数减一
    }
}
